package com.fifth.emp.controller;

import com.fifth.common.pojo.dto.CommonResult;
import com.fifth.common.pojo.entity.EmpInfo;
import com.fifth.emp.service.EmpService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @作者：徐志豪
 * @创建时间 2022/8/31 11:47
 **/
@RestController
@RequestMapping("/emp")
public class EmpController {
    @Autowired
    private EmpService empService;

    /**
     * 根据名字查询用户信息
     * @param ename
     * @return
     */
    @PostMapping("findByName/{ename}")
    public CommonResult findByName(@PathVariable String ename){
        return empService.findByName(ename);
    }

    /**
     * 添加员工
     * @param empInfo
     * @return
     */
    @PostMapping("insertEmp")
    public CommonResult insertEmp(@RequestBody EmpInfo empInfo){
        return empService.insertEmp(empInfo);
    }

    /**
     * 根据id删除员工
     */
    @PostMapping("deleteById/{id}")
    public CommonResult deleteById(@PathVariable String id){
        System.out.println("++++++++++++++++++"+id);
        return empService.deleteById(id);
    }

    /**
     * 修改员工信息
     * @param empInfo
     * @return
     */
    @PostMapping("/updateEmp")
    public CommonResult updateEmp(@RequestBody EmpInfo empInfo){
        return empService.updateEmp(empInfo);
    }

    /**
     * 连表查询全部包含员工角色信息
     * @return
     */
    @PostMapping("selectAll")
    public CommonResult selectAll(@RequestParam(defaultValue = "1") Integer currentPage, @RequestParam(defaultValue = "5") Integer pageSize, @RequestBody EmpInfo empInfo){
        return empService.selectAll(currentPage,pageSize,empInfo);
    }
    /**
     * 修改密码
     */
    @PostMapping("updatePassword/{oldPassword}/{newPassword}")
    public CommonResult updatePassword(@PathVariable String oldPassword,@PathVariable String newPassword){
        return empService.updatePassword(oldPassword,newPassword);
    }
}
